/*
 * @Author: fanyaqing
 * @Date: 2021-08-12 09:16:19
 * @LastEditTime: 2021-08-16 14:26:17
 * @LastEditors: fanyaqing
 * @Description: 
 * @FilePath: \supermall\src\store\actions.js
 */
export default {
  // 逻辑的事件和请求，尽量放到actions中
  addCart(context,payload){
    return new Promise((resolve,reject)=>{
      let oldProduct=context.state.cartList.find(res=>res.iid===payload.iid);//有相同的商品，count++，不同的count=1
      if(oldProduct){
        context.commit('addCounter',oldProduct)
        // oldProduct.count+=1;
        resolve('当前商品数量+1')
      }else{
        payload.count=1;
        context.commit('addToCart',payload)
        // context.state.cartList.push(payload)
        resolve('当前商品数量=1')
      }
    })
  }
}